package com.gitee.sop.layui.adminserver.module.background.admin.rest;

import com.gitee.sop.layui.adminserver.module.background.admin.service.SysMenuRoleRelationService;
import com.gitee.sop.layui.adminserver.module.base.constants.Result;
import com.gitee.sop.layui.adminserver.module.base.error.ServiceInterruptionException;
import com.gitee.sop.layui.adminserver.module.base.util.AssertUtil;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * com.zch.admin.base.entity.SysRoleMenuRelation模型http接口处理
 *
 * @author: admin
 * @date: 2019-11-13
 * @version: 1.0.0
 */
@RestController
@RequestMapping("/admin/menuRoleRelation")
public class SysMenuRoleRelationRestController {
    @Lazy
    @Resource
    private SysMenuRoleRelationService baseService;

    @RequestMapping(value = {"/setAuthority/{roleUuid}"})
    public Result setAuthority(@PathVariable(value = "roleUuid") String roleUuid, @RequestParam(value = "menuIds") Integer[] menuIds, String appId) {
        AssertUtil.isTrue(menuIds.length < 1000, ServiceInterruptionException.fail(400, "参数错误"));
        baseService.setAuthority(roleUuid, Arrays.stream(menuIds).collect(Collectors.toList()), appId);
        return Result.success();
    }
}
